package com.jyw.business.obstacles.domain.dto.web;

import com.google.common.collect.Lists;
import com.jyw.business.obstacles.domain.ObsOrderSend;
import com.jyw.common.utils.DateUtils;
import com.jyw.common.utils.SecurityUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.util.ObjectUtils;

import java.util.List;

/**
 * @author 沈峻
 * @ClassName AddOrderDto
 * @Description 创建工单请求实体
 * @Date 2023/8/10 15:34
 **/
@ApiModel("创建工单请求实体")
@Data
public class OrderAddDto extends BaseOrderAddDto{

    @ApiModelProperty("派单对象标识")
    private Long sendObjId;

    @Override
    public List<ObsOrderSend> buildSend() {
        ObsOrderSend send = new ObsOrderSend();
        //派单
        send.setType(1);
        //创建时间
        send.setCreateTime(DateUtils.getNowDate());
        if(getSendType().equals(1)){
            //由我处理
            send.setSendUser(SecurityUtils.getUserId());
            send.setSendTeam(getSendTeam());
            send.setSendType(1);
        }else{
            send.setSendType(getSendObjType());
            switch (getSendObjType()){
                case 1:
                    send.setSendUser(getSendObjId());
                    send.setSendTeam(getSendTeam());
                    break;
                case 2:
                    send.setSendTeam(getSendObjId());
                    break;
                case 3:
                    send.setSendDept(getSendObjId());
                    break;
            }
        }
        send.setCreateUser(SecurityUtils.getUserId());
        return Lists.newArrayList(send);
    }

    @Override
    public boolean canBuildSend() {
        return !ObjectUtils.isEmpty(getSendType())&&getSendType().equals(1)||!ObjectUtils.isEmpty(getSendObjId());
    }
}


